﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace FindDuplicateFile
{
    /// <summary>
    /// Interaction logic for GridDirectory.xaml
    /// </summary>
    public partial class GridDirectory : UserControl, INotifyPropertyChanged
    {
        public GridDirectory()
        {
            this.DataContext = this;
            InitializeComponent();

            SelectAction = null;
            ExportExcelAction = (grid) => ExportExcel();
        }

        public void ExportExcel()
        {
            FSDirectoryNode.ExportExcel(this.Directories);
        }

        private void mnuOpenFolder(object sender, RoutedEventArgs e)
        {
            FSNode node = (FSNode)this.gridDirectory.SelectedItem;
            if (node != null)
                node.OpenDirectory();
        }

        private void mnuExportExcel(object sender, RoutedEventArgs e)
        {
            if (ExportExcelAction != null)
                ExportExcelAction(this);
        }

        private void gridDirectory_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (SelectAction != null)
                SelectAction(this);
        }

        public Action<GridDirectory> SelectAction { get; set; }
        public Action<GridDirectory> ExportExcelAction { get; set; }

        public List<FSDirectoryNode> Directories
        {
            get { return (List<FSDirectoryNode>)GetValue(DirectoriesProperty); }
            set { SetValue(DirectoriesProperty, value); }
        }
        public static readonly DependencyProperty DirectoriesProperty = DependencyProperty.Register("Directories", typeof(List<FSDirectoryNode>), typeof(GridDirectory));

        public FSDirectoryNode CurrentDirectory 
        { 
            get 
            {
                return this.gridDirectory.CurrentItem as FSDirectoryNode; 
            } 
        }

        #region Fucking/Garbage for : INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion Fucking/Garbage for : INotifyPropertyChanged

    }
}
